#include <iostream>

#include <cmath>

#include <string>

#include <unordered_map>

#include <vector>

#include <sstream>


using namespace std;


bool isprime(int a) {

  for (int b = 2; b <= sqrt(a); b++) {

    if (a % b == 0) {

      return false;

    }

  }

  return true;

}


vector<string> split(const string& str, char delimiter) {

  vector<string> tokens;

  string token;

  istringstream tokenStream(str);

  while (getline(tokenStream, token, delimiter)) {

    tokens.push_back(token);

  }

  return tokens;

}


int main() {

  unordered_map<string, int> digits = {

    {"zero", 0},

    {"one", 1},

    {"two", 2},

    {"three", 3},

    {"four", 4},

    {"five", 5},

    {"six", 6},

    {"seven", 7},

    {"eight", 8},

    {"nine", 9}

  };


  string input;

  getline(cin, input); 


  string r = "";

  

  for (string i : split(input, ' ')) { 

    

    if (digits.find(i) != digits.end()) {

      r += to_string(digits[i]); // Заменяем слово на цифру

    } else {

      cout << "Wrong input" << endl;

      return 1;

    }

  }


  int r_int = stoi(r);

  int j = 0;

  int k = 0;


  for (int l = r_int; l < r_int * 1000; l++) {

    if (isprime(l)) {

      j = l;

      break;

    }

  }


  for (int z = r_int; z >= 2; z--) {

    if (isprime(z)) {

      k = z;

      break;

    }

  }


  if (r_int - k > j - r_int) {

    cout << j << endl;

  } else {

    cout << k << endl;

  }


  return 0;

}